<template>
  <view>
    <tn-button id="print_btn" @click="cusRenderDom" class="btn">打印</tn-button>

    <sp-html2pdf-render
        domId="render-dom"
        ref="renderRef"
        @beforeSavePDF="beforeSavePDF"
        @renderOver="renderOver"
        :auto-open="false"
    ></sp-html2pdf-render>
    <!--    :auto-open="false"-->
    <view id="render-dom">
      <view class="main">
        <view class="title">
          <view>文书备注</view>
        </view>
        <view class="box">
          <view class="shuoming">本卷情况说明</view>
          <view class="unline" style="width: 16em;text-align: center;">{{ jsonData.expl }}</view>
          <view class="content">{{ jsonData.explainMain }}</view>
          <view class="bottom-right">
            <view class="unline">立卷人 {{ jsonData.createPerson }}</view>
            <view class="unline">检查人 {{ jsonData.checkPerson }}</view>
            <view class="unline">立卷时间 {{ jsonData.createTi }}</view>
          </view>
        </view>
      </view>
    </view>
  </view>
</template>
<script>
import {base64ToPath} from "@/uni_modules/sp-html2pdf-render/utils";
import {uploadLp, uploadLpPdf} from "@/api/lupeiwenshu";
import {base64ToFile} from "@/utils/typeConversion";

export default {
  props: ['jsonData'],
  data() {
    return {
      reviewBaseImg: '',
      webImageBase: '',
      locImageBase: ''
    };
  },
  methods: {
    cusRenderDom() {
      this.$refs.renderRef.h2pRenderDom()
    },
    renderOver(e) {
      // e为导出的图片（base64）
      // console.log('e', e);
      const file = base64ToFile(e, 'fjtp', 'png');
      console.log(file)
      base64ToPath(e).then(path => {
        uploadLp({
          filePath: e
        }).then(res => {
          this.$emit('upload', {...res, path})
        }).catch(err => {
          console.log('err', err)
          this.$emit('upload', {code: 500})
        })

      })
    },
    beforeSavePDF(e) {
      // e为导出的pdf（base64）
      // console.log('==== beforeSavePDF :', e);
      return
      const file = base64ToFile(e, 'jzjp021212.pdf', 'pdf');
      base64ToPath(e).then(path => {

        // this.$emit('upload', {
        //   ...{
        //     code: 0,
        //     data: {
        //       url: 'http://47.92.235.205/lppdf/2025/08/13/1955435227065749506.pdf'
        //     }
        //   },
        //   path
        // })
        // return

        uploadLpPdf({
          file,
        }).then(res => {
          this.$emit('upload', {...res, path})
        }).catch(err => {
          console.log('err', err)
          this.$emit('upload', {code: 500})
        })
      })

    },
  }
};
</script>
<style scoped lang="scss">
#render-dom {
  width: 794px;
  height: 1123px;
  padding: 0px 77px 0;
  color: #000;
  .main {
    margin: 0 auto;
    font-family: "宋体";
    height: 100%;
  }

  .box {
    font-size: 16px;
    padding: 10px;
    position: relative;
    border: 1px solid #000;
    height: calc(100% - 140px - 140px);
  }

  .title {
    line-height: 140px;
    font-weight: bold;
    text-align: center;
    font-size: 28px;
    display: flex;
    flex-direction: column;
    justify-content: center;

  }

  .shuoming {
    margin-top: 2em;
    padding-left: 8em;
  }

  .unline {
    border-bottom: 1px solid #000;
    padding-bottom: 2px;
    line-height: 2em;
  }

  .content {
    text-indent: 2em;
    line-height: 2em;
  }

  .bottom-right {
    position: absolute;
    right: 0;
    bottom: 5px;

    view {
      width: 200px;
    }
  }
}

</style>
